﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESOL.Common.Entity;
using ESOL.Business.Prod;
using ESOL.WinUI.Hr;

namespace ESOL.WinUI.Manufacture
{
    public partial class frmManageReportWorkingList : BaseForm.frmBaseMdiChildForm
    {
        #region ctors
        public frmManageReportWorkingList()
        {
            InitializeComponent();
        }
        #endregion

        private void BindCombobox()
        {
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbWorkingOrderStatus, "POI", true);
        }

        private string GetCondition()
        {
            string sCondition = "";
            if (dtpReportTime.EditValue != null)
            {
                sCondition += " and pwr.REPORT_DATE>='" + ((DateTime)dtpReportTime.EditValue).ToString("yyyy-MM-dd 00:00:00") + "'";
            }
            if (dtpReportTimeTo.EditValue != null)
            {
                sCondition += " and pwr.REPORT_DATE<='" + ((DateTime)dtpReportTimeTo.EditValue).ToString("yyyy-MM-dd 23:59:59") + "'";
            }
            if (string.IsNullOrEmpty(cmbWorkingOrderStatus.SelectedValue.ToString()) == false)
            {
                sCondition += " and ppoi.STATUS='" + cmbWorkingOrderStatus.SelectedValue.ToString() + "'";
            }
            if (txtWorkingPerson.Tag != null)
            {
                sCondition += " and pwr.report_person='" + ((MstPersonEntity)txtWorkingPerson.Tag).PersonId + "'";
            }
            return sCondition;
        }

        private void BindGridMain()
        {
            string sCondition = GetCondition();
            DataTable dt = ProdWorkingReportBs.GetWorkingReportOverview(sCondition);
            gvMain.DataSource = dt;
            gridView1.ExpandAllGroups();
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            BindCombobox();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            BindGridMain();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog frm = new SaveFileDialog();
            frm.Filter = "All Files (*.*)|";
            frm.DefaultExt = "xls";
            frm.AddExtension = true;
            frm.FileName = "报工信息导出列表" + DateTime.Today.ToString("yyyy-MM-dd");
            if (frm.ShowDialog() == DialogResult.OK)
            {
                gvMain.ExportToXls(frm.FileName);
            }
        }

        private void txtWorkingPerson_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmMaintainEmployeeQuery frm = new frmMaintainEmployeeQuery(true);
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedPerson != null)
            {
                txtWorkingPerson.Text = frm.SelectedPerson.NameCn;
                txtWorkingPerson.Tag = frm.SelectedPerson;
            }
            else
            {
                txtWorkingPerson.Text = "";
                txtWorkingPerson.Tag = null;
            }
        }

    }
}
